package com.tudulist.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlRootElement
@Entity
@Table(name = "Users")
@NamedQueries({ @NamedQuery(name = "User.findAll", query = "SELECT c FROM User c"),
		@NamedQuery(name = "User.findByLogin", query = "SELECT c FROM User c WHERE c.login = :login") })
public class User implements Serializable {

	private static final long serialVersionUID = 1L;

	public static final String USER_FIND_ALL = "User.findAll";

	public static final String USER_FIND_BY_LOGIN = "User.findByLogin";

	@Id
	@GeneratedValue
	private long id;

	private String login;

	private String password;

	private String firstName;

	private String lastName;

	private String email;

	@OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.EAGER)
	private Set<Role> role = new HashSet<Role>();

	@OneToMany(mappedBy = "user", cascade = { CascadeType.REMOVE }, fetch = FetchType.EAGER)
	private Set<TodoList> todoLists = new HashSet<TodoList>();

	@Column
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime creationDate;

	@Column
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	private DateTime lastAccessDate;

	private boolean enabled;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public DateTime getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(DateTime creationDate) {
		this.creationDate = creationDate;
	}

	public DateTime getLastAccessDate() {
		return lastAccessDate;
	}

	public void setLastAccessDate(DateTime lastAccessDate) {
		this.lastAccessDate = lastAccessDate;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Set<Role> getRoles() {
		return this.role;
	}

	public void setRoles(Set<Role> role) {
		this.role = role;
	}

	public Set<TodoList> getTodoList() {
		return todoLists;
	}

	public void setTodoList(Set<TodoList> todoList) {
		this.todoLists = todoList;
	}

}
